<?php
class ecController{

  public static function getController($params = array(), $controllerList= array())
  {
    $value = strtolower($params['applicationName'].'/'.$params['moduleName'].'/'.$params['controllerName']);

    $controllerRoute = '';

    if(array_key_exists($value, $controllerList))
    {
      $controllerRoute = $controllerList[$value];

      //verification et insertion du controller pour traitement.
      if(Secure::includeVerif(dirname(__FILE__).'/../../../apps/'.$controllerRoute))
      {
        require_once dirname(__FILE__).'/../../../apps/'.$controllerRoute;

        // chargement de la classe ecAction et des actions du controller.
        $controllerClass = strtolower($params['controllerName']).'Action';

        $class = new $controllerClass($params);

        $showFunction = 'show'.ucfirst($params['actionName']);
        //chargement de la méthode de la classe action demandé.
        if(method_exists($class,$showFunction))
        {
          $class->$showFunction();
        }
        else{
          throw new Exception("this method {$showFunction}() doesnt exist in controller {$controllerClass}");
        }
      }
    }
    else{
      throw new Exception("this controller {$value} doesnt exist");
    }
  }
}
